package com.zengraoli.PointSystem.utils;

import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;

import java.util.HashMap;
import java.util.Map;

public class ReturnRes {
    public static JsonData returnCodeAndMsg(TransactionResponse response, String returnInfo) {
        Map<String, String> res = new HashMap<>();
        res.put("returnCode", response.getReturnCode()+"");
        res.put("returnMessage", response.getReturnMessage());
        if (response.getReturnCode() != 0) {
            return JsonData.buildError(response.getReturnMessage());
        }
        return JsonData.buildSuccess(res, returnInfo);
    }

    public static JsonData returnValue(TransactionResponse response, String fieldName, String returnInfo) {
        Map<String, String> res = new HashMap<>();
        res.put(fieldName, response.getReturnCode()+"");
        res.put("returnMessage", response.getReturnMessage());
        if ("Success".equals(response.getReturnMessage())) {
            return JsonData.buildSuccess(res, returnInfo);
        }
        return JsonData.buildError(response.getReturnMessage());
    }
}
